package ru.scan2d.main.system;

import java.awt.MenuBar;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JMenuBar;
import javax.swing.filechooser.FileNameExtensionFilter;

import ru.scan2d.main.MainWindowPresenter;
import ru.scan2d.main.impl.MainMenuBar;
import ru.scan2d.main.util.SettingsUtil;

public class ClientFactoryImpl implements ClientFactory {

	private static JFileChooser openFileChooser;
	private static JFileChooser saveFileChooser;

	public ClientFactoryImpl() {
		openFileChooser = new JFileChooser();
		openFileChooser.setFileFilter(new FileNameExtensionFilter(
				"Scan2D data files", "scan2d"));
		if (new File(SettingsUtil.getProperty(SettingsUtil.OPEN_CHOOSER)) != null) {
			openFileChooser.setCurrentDirectory(new File(SettingsUtil
					.getProperty(SettingsUtil.OPEN_CHOOSER)).getParentFile());
		}
		saveFileChooser = new JFileChooser();
		if (new File(SettingsUtil.getProperty(SettingsUtil.SAVE_CHOOSER)) != null) {
			saveFileChooser.setCurrentDirectory(new File(SettingsUtil
					.getProperty(SettingsUtil.SAVE_CHOOSER)).getParentFile());
		}

	}

	@Override
	public JFileChooser getOpenFileChooser() {
		return openFileChooser;
	}

	@Override
	public JFileChooser getSaveFileChooser() {
		return saveFileChooser;
	}

	@Override
	public JMenuBar getMainMenuBar(MainWindowPresenter.Listener listener) {
		return new MainMenuBar(this, listener);
	}

}
